package com.ibm.moa.outmail.view;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Color;
import android.os.Handler;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.ibm.moa.outmail.R;
import com.ibm.moa.outmail.module.MailInfo;

public class SearchMailListAdapter extends BaseAdapter{
	private ViewHolder holder;
	private Context context;
	private ArrayList<MailInfo> mailList;
	public SearchMailListAdapter(Context context, ArrayList<MailInfo> mailList, Handler handler){
		this.context = context;
		this.mailList = mailList;
	}

	@Override
	public int getCount() {
		return mailList.size();
	}

	@Override
	public Object getItem(int position) {
		return mailList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = View.inflate(context, R.layout.mail_list_uncheck_item, null);
			holder = new ViewHolder();
			holder.name = (TextView) convertView.findViewById(R.id.mail_list_item_name_tv);
			holder.date = (TextView) convertView.findViewById(R.id.mail_list_item_date_tv);
			holder.title = (TextView) convertView.findViewById(R.id.mail_list_item_title_tv);
			holder.fujian = (ImageView) convertView.findViewById(R.id.mail_list_item_fujian_flag);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder)convertView.getTag();
		}
		holder.name.setText(mailList.get(position).mailUserId);
		if(!mailList.get(position).readFlag){
			holder.name.setTextColor(Color.parseColor("#FF4ca986"));
		}else{
			holder.name.setTextColor(Color.BLACK);
		}
		if(mailList.get(position).haveAttach){
			holder.fujian.setVisibility(View.VISIBLE);
		}else{
			holder.fujian.setVisibility(View.GONE);
		}
		holder.title.setText(mailList.get(position).subject);
		holder.date.setText(mailList.get(position).sendDateFormat);
		
		return convertView;
	}
	
	class ViewHolder {
		TextView name;
		TextView date;
		TextView title;
		ImageView fujian;
	}

}
